/*
    8. Write a program in C to copy one string to another string. 

    Test Data :
    Input the string : This is a string to be copied.

    Expected Output :

    The First string is : This is a string to be copied.
    The Second string is : This is a string to be copied. 
    Number of characters copied : 31
*/

#include <stdio.h>
#include <stdlib.h>

char* getstr(char *str)
{
    char ch;
    char *p = str;
    while((ch = getchar()) != '\n'){
        *p = ch;
        p++;
    }
    *p = '\0';
    return str;
}

int getstrlen(char *str)
{
    int len = 0;
    char *p = str;
    while(*p != '\0'){
        len++;
        p++;
    }
    len++; // '\0'
    return len;
}

int strcpy(char *pdst, char *psrc)
{
    int cnt = 0;
    while(*pdst++ = *psrc++){        
        cnt++;
    }
    cnt++; // '\0'
    return cnt;
}

int main(void)
{
    char *str1 = malloc(1024);
    char *str2 = malloc(1024);
    int cnt = 0;
    printf("Input the string : ");
    getstr(str1);
    cnt = strcpy(str2, str1);
    printf("The First string is : %s\n", str1);
    printf("The Second string is : %s\n", str2);
    printf("Number of characters copied : %d\n", cnt);

    return 0;
}
